package com.hpin.fansea.my;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.hpin.fansea.base.BaseActivity;
import com.hpin.fansea.bean.MyRepairs;
import com.hpin.fansea.utils.Constant;
import com.hpin.fansea.widget.PreviewPhotoActivity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 我的报修详情
 * Created by Aaron on 15/9/22.
 */
public class MyRepairsDetailActivity extends BaseActivity {

    private MyRepairs.RepairDetail repairDetail;

//    private TextView phone;
    private DisplayImageOptions options;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_repair_detail);

        repairDetail = (MyRepairs.RepairDetail) getIntent().getSerializableExtra("repairDetailList");

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.icon_headpic_default)
                .showImageForEmptyUri(R.mipmap.icon_headpic_default)
                .showImageOnFail(R.mipmap.icon_headpic_default)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true).cacheInMemory(true)
                .cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .displayer(new SimpleBitmapDisplayer()).build();

        initWidget();

    }

    private void initWidget() {

        ImageView iv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);

        tv_title.setText(getResources().getString(R.string.my_repair_record));

        iv_left.setOnClickListener(this);

        ImageView repair_detail_img = (ImageView) findViewById(R.id.repair_detail_img);
        TextView address = (TextView) findViewById(R.id.repair_detail_address);
        TextView contacts = (TextView) findViewById(R.id.repair_detail_contacts);
        TextView tvPhone = (TextView) findViewById(R.id.repair_detail_tvPhone);
        TextView reason = (TextView) findViewById(R.id.repair_detail_reason);
        // 报修电话
//        phone = (TextView) findViewById(R.id.repair_detail_phone);
//        LinearLayout llPhone = (LinearLayout) findViewById(R.id.repair_detail_llPhone);

        address.setText(sp.getString(Constant.communityId, "") + "期"
                + sp.getString(Constant.buildingNo, "") + sp.getString(Constant.unitNo, "")
                + sp.getString(Constant.houseNo, ""));

        if (repairDetail != null) {

            ImageLoader.getInstance().displayImage(repairDetail.fmpic, repair_detail_img, options);

            contacts.setText(repairDetail.maintenanceUserid);
            tvPhone.setText(repairDetail.phoneNum);
            reason.setText(repairDetail.maintenanceCont);
        }

        repair_detail_img.setOnClickListener(this);
//        llPhone.setOnClickListener(this);

    }

    @Override
    public void widgetClick(View v) {
        switch (v.getId()) {

            case R.id.iv_left:
                finish();
                break;

//            case R.id.repair_detail_llPhone:
//                // 打电话,提示对话框
//                new AlertDialog.Builder(this).setTitle("提示").setMessage("是否要拨打电话")
//                        .setPositiveButton("确定",
//                                new DialogInterface.OnClickListener() {
//                                    @Override
//                                    public void onClick(DialogInterface arg0, int arg1) {
//                                        String phoneNum = phone.getText().toString().trim();
//
//                                        if (!CommonUtils.isPhone(phoneNum)) {
//                                            showToast("未获取到正确的手机号码");
//                                            return;
//                                        }
//
//                                        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNum));
//                                        startActivity(intent);
//
//                                    }
//                                }).setNegativeButton("取消", null).show();
//
//                break;

            case R.id.repair_detail_img:

                //点击查看大图

                if (repairDetail == null)
                    return;

                List<String> picLists = new ArrayList<String>();

                picLists.add(repairDetail.fmpic);

                Intent mIntent = new Intent(this, PreviewPhotoActivity.class);
                mIntent.putExtra("picLists", (Serializable) picLists);
                startActivity(mIntent);

                break;

            default:
                break;
        }
    }
}